package com.employee.controller;

import com.employee.pojo.dto.DeptDTO;
import com.employee.pojo.dto.DeptUpdateDTO;
import com.employee.pojo.entry.Dept;
import com.employee.pojo.entry.DeptHistory;
import com.employee.pojo.result.Result;
import com.employee.pojo.vo.DeptEmpVO;
import com.employee.pojo.vo.DeptInfoVO;
import com.employee.pojo.vo.DeptVO;
import com.employee.service.DeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class DeptController {
    @Autowired
    private DeptService deptService;

    // 获取员工部门历史记录
    @GetMapping("/getDeptHis/{id}")
    public Result<List<DeptHistory>> getDeptList(@PathVariable("id") Long id) {
        return Result.success(deptService.getDeptList(id));
    }


    //    部门列表查询
    @GetMapping("/getDeptListInfo")
    public Result<List<DeptVO>> getDeptListInfo(){

        return Result.success(deptService.getDeptListInfo());
    }

    //传入deptid查询并显示
    @GetMapping("/selectDeptInfo/{id}")
    public Result<DeptInfoVO> selectDeptInfo(@PathVariable Integer id) {

        System.out.println("-----------" + id);

        return Result.success(deptService.selectDeptInfo(id));
    }
    //查询部门下员工
    @GetMapping("/getDeptEmp/{id}")
    public Result<List<DeptEmpVO>> getDeptEmp(@PathVariable Integer id) {

        return Result.success(deptService.getDeptEmp(id));

    }

    //添加部门
    @PostMapping("/addDept")
    public Result addDept(@RequestBody DeptDTO deptDTO) {
        if (deptDTO != null) {
            System.out.println(deptDTO);
            deptService.addDept(deptDTO);
            return Result.success();
        } else {
            System.out.println("数据为空");
            return null;
        }
    }
    //实现搜索功能
    @GetMapping("/selectByNameAndStatus")
    public Result<List<DeptVO>>  selectByNameAndStatus
    (@RequestParam("deptName") String deptName,@RequestParam("status")String status){
        return Result.success(deptService.selectByNameAndStatus(deptName,status));

    }


//实现修改功能
    @PostMapping("/updateDept")
    public Result updateDept(@RequestBody DeptUpdateDTO updateDept){
        System.out.println(updateDept);
        deptService.updateDept(updateDept);
        return Result.success();
    }
    //修改状态
    @GetMapping("/updateStatus")
    public Result updateStatus(@RequestParam Integer id,@RequestParam String status ){
        System.out.println("--------------"+id+status);
        deptService.updateStatus(id,status);
        return Result.success();
    }

}

